<?php
require_once("../../../config.inc.php");
$isReloadable = true;
require_once("../../../app/_inc/include.php");
require_once("moduleFunction.php");

$errMsg = "";
$module = "";
$description = "";
$note = "";
if(isset($_REQUEST["reqtype"])){
	if($_REQUEST["reqtype"] == "save"){
		$errMsg .= moduleMod();
	}else if(isset($_REQUEST["reqtype"]) && $_REQUEST["reqtype"] == "delete"){
		$errMsg .= moduleDel();
	}
	$module = sxREQUEST("module");
	$description = sxREQUEST("description");
	$note = sxREQUEST("note");
}else {
	$module = sxREQUEST("mod");
}

$sSQL = "SELECT * FROM module " .
			"WHERE module = '".$module."'";
$objSDAO->query($sSQL, "mod");
if($row = $objSDAO->fetch("mod")){
	$module = $row["module"];
	$description = $row["description"];
	$note = $row["note"];
	
}else{
	$errMsg .= _t("no module '%s' found",$module)."<br>";
}

//docs retrieving
$sSQL = "SELECT * FROM module_doc WHERE module='$module'";
$objSDAO->query($sSQL, "doc");
$sSQL = "SELECT fa.*, m.description AS mdes FROM  module m " .
		" LEFT JOIN functional_area fa ON fa.module = m.module " .
		" WHERE m.module = '$module' " .
		" ORDER BY fa.functional_area ";
$query = $objSDAO->query($sSQL,'selfuar');

//output HTML
$aOpz = array("kMenu"=>'pro.mod', "isReloadable"=>$isReloadable);
echo(headerHTML($aOpz));
?>
<script language="JavaScript" type="text/javascript" src="../../_jsc/form.js"></script> 
<?php
echo(bodyHTML($aOpz));
//form 
echo("<form name=\"objFrm\" id=\"objFrm\" action=\"moduleView.php\" method=\"POST\">");
echo("<input type=\"hidden\" name=\"reqtype\" id=\"reqtype\" value=\"\">");
echo("<input type=\"hidden\" name=\"xsn\" value=\"".XSN."\">");
echo("<table width=\"100%\" cellpadding=\"03\" cellspacing=\"0\">\n<tr>\n<td>\n");
$aCmd = array(	
					"afun"=>array("pag"=>"../modl/functionalAreaIns.php?mod=$module",
										"title"=>_t("Add new functional-area"),
										"text"=>_t("new functional-area"),
										"perm"=>"viewmod",
										"align"=>"R"),
					"mod"=>array("pag"=>"moduleMod.php?mod=$module",
										"title"=>_t("change module"),
										"text"=>_t("change"),
										"perm"=>"viewmod"),
					"del"=>array("pag"=>"javascript:confirmDelete();",
										"title"=>_t("delete module"),
										"text"=>_t("delete"),
										"perm"=>"viewmod"),
					"lay"=>array("pag"=>"../layo/layoutSetList.php?mod=$module",
										"title"=>_t("Lista dei layout set"),
										"text"=>_t("layout set"),
										"perm"=>"viewmod",
										"align"=>"L"),
					"comRule"=>array("pag"=>"../crul/crulList.php?mod=$module",
										"title"=>_t("List of common rules"),
										"text"=>_t("common rules"),
										"perm"=>"viewmod",
										"align"=>"L"),
					"menu"=>array("pag"=>"../menu/menuPageList.php?mod=$module",
										"title"=>_t("List of menu pages"),
										"text"=>_t("menu"),
										"perm"=>"viewmod",
										"align"=>"L"),
					"back"=>array("pag"=>$objUser->getHistory(-1,false),
										"title"=>$objUser->getHistoryText(-1),
										"text"=>$objUser->getHistoryText(-1)
										)
					);
echo(commandsHTML($aCmd));	
echo("<table width=\"100%\" cellpadding=\"3\" cellspacing=\"2\" border='0'>\n");
echo("<tr>" .
			"<td class=\"titl01\" colspan='3'>"._t("Module")."</td>" .
		"</tr>\n");
echo("<tr>" .
			"<td class=\"labl01\" width=\"10%\">"._t("Name")."</td>" .
			"<td class=\"text01\" width=\"50%\">$module<input class=\"inpt01\" type=\"hidden\" name=\"module\" id=\"module\" maxlength=\"32\" value=\"$module\"></td>" .
			"<td class=\"labl01\" width=\"40%\">Documents</td>" .
		"</tr>\n");
$sDocList = '';
$nn=0;
while($row = $objSDAO->fetch("doc")){
	$nn++;
	$sDocList .= "$nn) <a class=\"text01\" target=\"blank\" href=\"getDoc.php?mod=$module&fn="
		.$row["file_name"]."&xsn=".XSN."\">".sxHE($row["name"])."</a><br/>\n" ;
	
}
echo("<tr>" .
			"<td class=\"labl01\">"._t("Description")."</td>" .
			"<td class=\"text01\">".sxHE($description)."</td>" .
			"<td class=\"text01\" rowspan='2' valign='top'>$sDocList</td>" .
		"</tr>\n");
echo("<tr>" .
			"<td class=\"labl01\">"._t("Note")."</td>" .
			"<td class=\"text01\"><pre class=\"text01\">".sxWW(sxHE($note))."</pre></td>" .
		"</tr>\n");
echo("</table>\n");
echo("<table class='tabl01' width=\"100%\" cellpadding=\"3\" cellspacing=\"2\">\n");
echo("<tr>" .
		"<td class=\"titl01\"colspan=\"3\">List of Functional-Areas</td>" .
	 "</tr>\n");
echo("<tr>" .
		"<td class=\"tabh01\" width=\"20%\">"._t("Name")."</td>" .
		"<td class=\"tabh01\" width=\"39%\">"._t("Description")."</td>" .
		"<td class=\"tabh01\" width=\"40%\">"._t("Note")."</td>" .
	"</tr>\n");
while($row = $objSDAO->fetch('selfuar')){
	if($row['functional_area']!=''){
		$numElem ++;
		echo("<tr>" .
				"<td class=\"text01\" valign='top'><a class=\"text01\" ".
				goToPag("functionalAreaView.php?fa=".$row["functional_area"]."&mod=".$row["module"]."&xsn=".XSN).
				" title=\""._t("Modifica area funzionale")."\">".$row["functional_area"]."</a></td>\n" .
				"<td class=\"text01\" valign='top'>".$row["description"]."</td>\n" .
				"<td class=\"text01\" valign='top'><pre class='text01'>".$row["note"]."</pre></td>\n" .
			"</tr>\n");
	}	
}
if($numElem == 0)
	echo("<tr>" .
			"<td class=\"text01\" colspan=\"4\">"._t("No functional-area")."</td>".
		"</tr>\n");
echo("</table>\n");
echo(commandsHTML($aCmd));

echo("</td>\n</tr>\n</table>\n");
echo("</form>");
echo(footerHTML());
